package com.neuedu.factory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ClassFactory {
    public static Object createObj(String name){
        //如何能够改变dao，但是我的service中代码不变
        //读取配置文件
        InputStream in = ClassFactory.class.getResourceAsStream("application.properties");
        Properties properties = new Properties();
        try {
            properties.load(in);
            //反射创建对象
            return Class.forName(properties.getProperty(name)).newInstance();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
